#include "cpu/exec/template-start.h"

#define instr sar

static void do_execute () {
	//提取src和dest的值
	switch (op_src->type) {
		case OP_TYPE_REG:
			switch (op_dest->reg) {
				case 0: op_src->val = cpu.eax; break;
				case 1: op_src->val = cpu.ecx; break;
				case 2: op_src->val = cpu.edx; break;
				case 3: op_src->val = cpu.ebx; break;
				case 4: op_src->val = cpu.esp; break;
				case 5: op_src->val = cpu.ebp; break;
				case 6: op_src->val = cpu.esi; break;
				case 7: op_src->val = cpu.edi; break;
				default: Assert(0, "op_dest->reg = %d", op_dest->reg);
			}
			break;
		case OP_TYPE_MEM:
			op_src->val = swaddr_read(op_src->addr, DATA_BYTE);
			break;
		case OP_TYPE_IMM:
			break;
	}
	switch (op_dest->type) {
		case OP_TYPE_REG:
			switch (op_dest->reg) {
				case 0: op_dest->val = cpu.eax; break;
				case 1: op_dest->val = cpu.ecx; break;
				case 2: op_dest->val = cpu.edx; break;
				case 3: op_dest->val = cpu.ebx; break;
				case 4: op_dest->val = cpu.esp; break;
				case 5: op_dest->val = cpu.ebp; break;
				case 6: op_dest->val = cpu.esi; break;
				case 7: op_dest->val = cpu.edi; break;
				default: Assert(0, "op_dest->reg = %d", op_dest->reg);
			}
			break;
		case OP_TYPE_MEM:
			op_dest->val = swaddr_read(op_dest->addr, DATA_BYTE);
			break;
		default: Assert(0, "op_dest->type = %d", op_dest->type);
	}
	uint8_t src = op_src->val;
	DATA_TYPE dest = op_dest->val;

	uint8_t count = src & 0x1f;
	dest >>= count;
	// OPERAND_W(op_dest, dest);
	//赋值
	switch (op_dest->type) {
		case OP_TYPE_REG:
			switch (op_dest->reg) {
				case 0: cpu.eax = dest; break;
				case 1: cpu.ecx = dest; break;
				case 2: cpu.edx = dest; break;
				case 3: cpu.ebx = dest; break;
				case 4: cpu.esp = dest; break;
				case 5: cpu.ebp = dest; break;
				case 6: cpu.esi = dest; break;
				case 7: cpu.edi = dest; break;
				default: Assert(0, "op_dest->reg = %d", op_dest->reg);
			}
			break;
		case OP_TYPE_MEM:
			swaddr_write(op_dest->addr, DATA_BYTE, dest);
			break;
		default: Assert(0, "op_dest->type = %d", op_dest->type);
	}

	update_eflags_pf_zf_sf(dest);

	print_asm_template2();
}

make_instr_helper(rm_1)
make_instr_helper(rm_cl)
make_instr_helper(rm_imm)

#include "cpu/exec/template-end.h"
